/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package folder.helper;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 
 * @author ST
 */
public final class Folders {
	// sollte in eine INI Datei und aus dieser bei
	// Programmstart in die Variablen geladen werde
	public static final String SEP = File.separator;
	public static String main_Folder;
	// public static String element_Listings = main_Folder +
	// "\\LayoutElements_XML\\";
	// public static String standard_Save_Path = main_Folder +
	// "\\Saved_Layouts\\";
	// public static String standard_Save_Filename = null;
	// public static String choosen_Save_Path = main_Folder +
	// "\\Saved_Layouts\\";
	public static String element_Listings;
	public static String standard_Save_Path;
	public static String standard_Save_Filename = null;
	public static String choosen_Save_Path;

	// public static String Choosen_Save_Filename = "New_Layout.xml";

	public Folders(String mainPath, String mainClassName) {
		main_Folder = folders(mainPath, mainClassName);
		element_Listings = main_Folder + SEP + "LayoutElements_XML" + SEP;
		choosen_Save_Path = main_Folder + SEP + "Saved_Layouts" + SEP;
	}

	public static String getChoosenSaveFilenameSuggestion() {
		String s = "";
		String timestamp = new SimpleDateFormat("yyyy_MM_dd-HHmmss")
				.format(new Date());
		s += "New_Layout_" + timestamp + ".xml";
		standard_Save_Filename = s;
		return s;
	}

	public static String getStandardSaveFileName() {
		if (standard_Save_Filename == null) {
			String s = "";
			String timestamp = new SimpleDateFormat("yyyy_MM_dd-HHmmss")
					.format(new Date());
			s += "New_Layout_" + timestamp + ".xml";
			standard_Save_Filename = s;
		}
		return standard_Save_Filename;
	}

	public static void setChoosenSavePath(String path) {
		choosen_Save_Path = path;
	}

	public String folders(String mainPath, String mainClassName) {
		// System.out.println("mainPAth: " + mainPath);
		// System.out.println("mainClassName: " + mainClassName);
		String ret = null;
		int i = 0;
		String[] pathParts = mainPath.split("/");
		i = pathParts.length;
		// System.out.println("Split: " + i);
		// if (pathParts[i - 1].equalsIgnoreCase(mainClassName + ".class")) {
		if (i - 1 >= 0) {
			for (int a = 0; a < i; a++) {
				if (pathParts[a].equals("LayoutEditor")) {
					ret = pathParts[1] + SEP;
					for (int b = 2; b <= a - 1; b++) {
						ret += pathParts[b] + SEP;
						// System.out.println("Main_Folder: " + ret);
					}
					ret += pathParts[a];
					// System.out.println("Main_Folder: " + ret);
				}
			}
			// }
			// for Linux file System
			if (mainPath.startsWith(SEP)){
				ret = SEP+ret;
			}
		}
		return ret;
	}
	// public String folders(String mainPath, String mainClassName) {
	// //System.out.println("mainPAth: " + mainPath);
	// //System.out.println("mainClassName: " + mainClassName);
	// String ret = null;
	// int i = 0;
	// String[] pathParts = mainPath.split("\\\\");
	// i = pathParts.length;
	// //if (pathParts[i - 1].equalsIgnoreCase(mainClassName + ".class")) {
	// if (i - 1 >= 0) {
	// for (int a = 0; a < i - 1; a++) {
	// if (pathParts[i - 1 - a].equals("LayoutEditor")) {
	// ret = pathParts[0] + "\\";
	// for (int b = 1; b <= a - 1; b++) {
	// ret += pathParts[b] + "\\";
	// //System.out.println("Main_Folder: " + ret);
	// }
	// ret += pathParts[a];
	// System.out.println("Main_Folder: " + ret);
	// }
	// }
	// // }
	// }
	// return ret;
	// }
}
